package com.gzx.bi.modular.project.mapper;

import com.gzx.bi.modular.project.entity.GzxProjectDebt;
import com.gzx.bi.modular.project.vo.GzxProjectDebtVo;
import com.gzx.bi.modular.user.vo.GzxUserDebtVo;
import com.gzx.tjzy.feign.resp.project.GzxProjectRespDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 项目的在催案件和在催人力
 */
public interface GzxProjectDebtMapper extends BaseMapperPlus<GzxProjectDebt, GzxProjectDebtVo> {

    //插入数据，存在则更新，不存在则插入
    @Insert({
            "<script>",
            "insert into gzx_project_debt(project_code,project_name,case_load,debt_user) " +
                    "values " +
                    " <foreach collection='list' item='item' separator=','>" +
                    " (#{item.projectCode},#{item.projectName},#{item.caseLoad},#{item.debtUser}) " +
                    " </foreach> " +
                    " on duplicate key update case_load = values(case_load),debt_user = values(debt_user) " +
                    "</script>"
    })
    void insertUpdateBatch(List<GzxProjectRespDto> list);

    //获取项目的在催案件量和人力
    @Select("<script>" +
            "select project_code projectCode,debt_user debtUser,case_load caseLoad from gzx_project_debt " +
            " where project_code in " +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "   #{item.projectCode}" +
            "</foreach>" +
            "</script>")
    List<GzxProjectDebtVo> getProjectDebt(List<GzxUserDebtVo> list);
}
